<template>
	<view>
		<!-- <comlist title="创建转诊记录" :listtitle="listtitle" @comSearch="comSearch" :nullData="nullData" :listLabel="listLabel" :list="list" :options="options" :addpageUrl="'/pages/quickly/referral/entryPage'" @bindClick="bindClick" @jump="jump"></comlist> -->
		<publicList :list="list" :addpageUrl="'/pages/quickly/referral/entryPage'" @detail='detail'  :options="options" @bindClick="bindClick" :nullData="nullData"  @search="search"></publicList>
		<u-modal v-model="showModal" :show-cancel-button="true" @confirm="Modalconfirm" :content="showContent"></u-modal>
	</view>
</template>

<script>
	import publicList from '@/components/publicList/index.vue'
	import {filterData2} from '@/static/js/filter.js'
	export default {
		components:{publicList},
		data() {
			return  {
				showModal:false,
				showContent:'',
				list: null,
				listLabel:[
					{
						name:'转诊编号：',
						key:'sn'
					},
					{
						name:'转诊时间：',
						key:'referralDate'
					},
				],
				listtitle:'',
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#EE2437' // 删除按钮背景  红的
					}
				}],
				name: '',
				page: 1,
				nullData:false,
				deleteList: '',
				searchVal:''
			}
		},
		onLoad() {
			this.getlist({pageIndex:1,pageSize:10,userId:this.SearchuserId})
			// this.getlist({pageIndex:1,pageSize:20,name:this.name})
		},
		onReachBottom(){
			if(this.nullData == true){
				return;
			}
			this.page = this.page + 1
			this.getlist({pageSize:10,pageIndex:this.page,name:this.name,userName:this.searchVal})
		},
		methods:{
			search(e) {
				this.page = 1
				this.nullData = false
				this.searchVal = e
				this.$api.AppHealthReferralRecordsList({pageSize:10,pageIndex:1,userName:e}).then(res=>{
					var data = res.data.result && res.data.result.elements.map((a)=>{
						if(a.type == 1){
							a.listtitle = '双向转诊(转出)单'
						}else{
							a.listtitle = '双向转诊(回转)单'
						}
						return a
					})
					this.list = data
					if(this.list.length >= res.data.result.totalCount){
						this.nullData = true;
					}
				})
			},
			filterData2,
			getlist(data){
				const _this = this;
				_this.$api.AppHealthReferralRecordsList(data).then(res=>{
					var data = res.data.result && res.data.result.elements.map((a) => {
						if(a.type == 1){
							a.listtitle = '双向转诊(转出)单'
						}else{
							a.listtitle = '双向转诊(回转)单'
						}
						return a
					});
					if(_this.deleteList == 1) {
						_this.list = []
						_this.list = data
						_this.deleteList = ''
					}else {
						_this.list = _this.list ? _this.list.concat(data) : data
						if(_this.list.length >= res.data.result.totalCount){
							_this.nullData = true;
						}
					}
				})
			},
			bindClick(e){
				this.showModal = true
				this.showContent = '是否删除此转诊记录'
				this.delItem = e
			},
			Modalconfirm(){
				this.$api.AppHealthReferralRecordsDelete(this.delItem.id).then((res)=>{
					if(res.data.returnCode == 200){
						uni.showToast({
							title:'删除成功',
							icon:'none'
						})
						this.page = 1
						this.deleteList = 1;
						this.nullData = false;
						this.getlist({pageIndex:1,pageSize:10,userName:this.searchVal})
					}
				})
			},
			detail(item){
				if(item.type == 1) {
					!item.status || item.status == 1?
						uni.navigateTo({url:'/pages/quickly/referral/outOrder?id='+item.id})
					:
						uni.navigateTo({url:'/pages/quickly/referral/toView?id='+item.id})
				} else {
					!item.status || item.status == 1?
						uni.navigateTo({url:'/pages/quickly/referral/rotationOrder?id='+item.id})
					:
						uni.navigateTo({url:'/pages/quickly/referral/toView1?id='+item.id})
				}
				
			}
		}
	}
</script>

<style>
</style>
